package com.stellar.circle.controller.miniApp.sPostTag;

import com.google.common.base.Preconditions;
import com.stellar.circle.controller.admin.sPostTag.vo.HotTopicVO;
import com.stellar.circle.controller.admin.sPostTag.vo.SPostTagRequestPageVO;
import com.stellar.circle.controller.admin.sPostTag.vo.SPostTagResponseVO;
import com.stellar.circle.domain.sPostTag.SPostTagDomainService;
import com.stellar.web.core.bean.PageResult;
import com.stellar.web.core.bean.Result;
import com.stellar.web.core.constants.AuthUserConstants;
import com.stellar.web.core.validator.ValidatorRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 话题表控制器
 *
 * @author Jqchan
 * @version 1.0
 * @date 2025-05-17 19:30:33
 */
@RequestMapping("/api-miniApp/sPostTag")
@RestController("miniAppSPostTagController")
@Slf4j
public class SPostTagController {

    @Resource
    private SPostTagDomainService sPostTagDomainService;

    /**
     * 分页查询话题
     * isCurrentSchool：0-当前学校/1-全部话题
     * schoolId：学校Id - 不管查询范围如何都为必传
     */
    @PostMapping("/page")
    public Result<PageResult<SPostTagResponseVO>> pageForMiniApp(@RequestBody SPostTagRequestPageVO requestPageVO) {
        try {
            if (log.isInfoEnabled()) {
                Preconditions.checkNotNull(requestPageVO, "分页参数不能为空");
                Preconditions.checkNotNull(requestPageVO.getSchoolId(), "学校Id不能为空");
                Preconditions.checkNotNull(requestPageVO.getIsCurrentSchool(), "话题范围不能为空");
            }
            return Result.success(sPostTagDomainService.pageForMiniApp(requestPageVO));
        } catch (IllegalArgumentException iae) {
            return Result.fail(iae.getMessage());
        }

    }

    /**
     * 获取热门话题排行
     *
     * @return
     */
    @GetMapping("/hotRank")
    public Result<List<HotTopicVO>> getHotTopics() {
        return Result.success(sPostTagDomainService.getHotTopics());
    }


}
